"""
# -*- coding: utf-8 -*-
# @Time    : 2023/6/5 9:49
# @Author  : 王摇摆
# @FileName: Data2.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
# X为样本特征，Y为样本簇类别，共1000个样本，每个样本3个特征，共4个簇
from sklearn.datasets import make_blobs
from sklearn.decomposition import PCA

X, y = make_blobs(n_samples=10000, n_features=3, centers=[[3, 3, 3], [0, 0, 0], [1, 1, 1], [2, 2, 2]],
                  cluster_std=[0.2, 0.1, 0.2, 0.2],
                  random_state=9)

# 直接指定降维的维度，而指定降维后的主成分方差和比例
pca = PCA(n_components=0.99)
pca.fit(X)
print(pca.explained_variance_ratio_)
print(pca.explained_variance_)
print(pca.n_components_)
